package com.anxinr.excptionhandle;


import com.anxinr.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * 全局统一异常处理
 * @author anxinr
 */
@RestControllerAdvice
@Slf4j
public class ExceptionHandler {
    /**
     * 未知异常
     * */
    @org.springframework.web.bind.annotation.ExceptionHandler(Exception.class)
    public Result<Object> handleGlobalException(Exception e, HttpServletRequest request) {
        log.error("捕捉到未知异常 -> {}",e);
        return Result.fail(e.getMessage()) ;
    }
}
